-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[bsp][gd32]:gd32vw553h-eval add wdt support #11181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[bsp][gd32]:gd32vw553h-eval add wdt support #11181
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
请为wdt驱动添加ci-attach 参考:https://club.rt-thread.org/ask/article/5edd0f0940a57129.html |
| select RT_SERIAL_USING_DMA | ||
| default n | ||
|
|
||
| config BSP_USING_UART3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分串口和此pr不太相关,有必要提交上来吗?
| #include <board.h> | ||
| #include <rtthread.h> | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请删除多余的换行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR aims to add Watchdog Timer (WDT) support for the GD32VW553H-EVAL BSP by introducing a new WDT driver, wiring it into the GD32 RISC-V driver build, and exposing WDT-related Kconfig options for the board.
Changes:
- Add a new GD32 RISC-V watchdog driver (
drv_wdt.c) implementing RT-Thread watchdog device ops. - Update
SConscriptto compile the WDT driver whenRT_USING_WDT+SOC_GD32VW553Hare enabled. - Extend board Kconfig to expose WDT options (and also UART3/UART4 options).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 11 comments.
| File | Description |
|---|---|
| bsp/gd32/risc-v/libraries/gd32_drivers/drv_wdt.c | New watchdog driver implementation plus shell test commands |
| bsp/gd32/risc-v/libraries/gd32_drivers/SConscript | Adds conditional compilation of drv_wdt.c for GD32VW553H |
| bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig | Adds board-level WDT configs (and UART3/4 related configs) |
| rt_device_control(hw_dev, RT_DEVICE_CTRL_WDT_START, RT_NULL); | ||
| rt_device_control(hw_dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, RT_NULL); | ||
| } |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[bug/类别: bug]: Test sample functions return type mismatch / 测试示例函数返回类型与返回值不匹配
English: fwdt_test_sample() / wwdt_test_sample() are declared to return int but exit without returning a value. This can trigger compiler warnings or errors (often treated as -Werror in CI). Please return a proper status code on success paths.
中文:fwdt_test_sample() / wwdt_test_sample() 声明为返回 int,但函数末尾没有返回值。这会触发编译警告甚至错误(CI 常用 -Werror)。建议在成功路径返回明确的状态码。
| config BSP_USING_UART3 | ||
| bool "Enable UART3" | ||
| default n | ||
|
|
||
| config BSP_UART3_RX_USING_DMA | ||
| bool "Enable UART3 RX DMA" | ||
| depends on BSP_USING_UART3 | ||
| select RT_SERIAL_USING_DMA | ||
| default n | ||
|
|
||
| config BSP_USING_UART4 | ||
| bool "Enable UART4" | ||
| default n | ||
|
|
||
| config BSP_UART4_RX_USING_DMA | ||
| bool "Enable UART4 RX DMA" | ||
| depends on BSP_USING_UART4 | ||
| select RT_SERIAL_USING_DMA | ||
| default n |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[discrepancy_with_pr_description/类别: discrepancy_with_pr_description]: PR includes UART3/4 Kconfig changes not mentioned / PR 包含未在描述中说明的 UART3/4 配置变更
English: This PR is titled/justified as adding WDT support, but this Kconfig hunk also introduces UART3/UART4 (and DMA) options. If these UART options are required for WDT support, please explain the dependency in the PR description; otherwise, consider moving UART-related changes into a separate PR to keep the change set focused.
中文:本 PR 标题/说明是新增 WDT 支持,但该 Kconfig 片段同时新增了 UART3/UART4(及 DMA)选项。如果这些 UART 选项与 WDT 支持存在依赖关系,请在 PR 描述中说明原因;否则建议将 UART 相关修改拆分到单独 PR,保持改动聚焦。
| if GetDepend(['RT_USING_WDT', 'SOC_GD32VW553H']): | ||
| src += ['drv_wdt.c'] |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[discrepancy_with_pr_description/类别: discrepancy_with_pr_description]: PR description template not filled (verification/config/action) / PR 描述模板未填写(验证信息/配置/action)
English: The PR description still contains the unfilled template sections and does not provide the verified BSP path, relevant .config changes, or CI/action link. RT-Thread’s PR template requires these details for review and reproducibility; please complete them before merge.
中文:PR 描述仍保留未替换的模板内容,且未提供已验证的 BSP 路径、关键 .config 变更以及 CI/action 链接。RT-Thread 的 PR 模板要求这些信息用于审查与复现,建议在合入前补充完整。
| #if defined(BSP_USING_FWDT) | ||
| #define HW_WDGT_DEV_NAME "fwdgt" | ||
| #elif defined(BSP_USING_WWDT) | ||
| #define HW_WDGT_DEV_NAME "wwdgt" |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[bug/类别: bug]: HW_WDGT_DEV_NAME can be undefined / HW_WDGT_DEV_NAME 可能未定义导致编译失败
English: HW_WDGT_DEV_NAME is only defined when BSP_USING_FWDT or BSP_USING_WWDT is set. It is later used unconditionally, so enabling WDT without selecting a concrete type will break the build. Please add a compile-time check (#error) here or enforce a choice in Kconfig to guarantee exactly one implementation.
中文:HW_WDGT_DEV_NAME 只在定义了 BSP_USING_FWDT 或 BSP_USING_WWDT 时才会生成;后续代码会无条件使用它,因此开启 WDT 但未选择具体类型会导致编译失败。建议在此处增加编译期检查(#error),或在 Kconfig 中用 choice 保证只能且必须选择一种实现。
| #if defined(BSP_USING_FWDT) | |
| #define HW_WDGT_DEV_NAME "fwdgt" | |
| #elif defined(BSP_USING_WWDT) | |
| #define HW_WDGT_DEV_NAME "wwdgt" | |
| #if defined(BSP_USING_FWDT) && defined(BSP_USING_WWDT) | |
| #error "Only one of BSP_USING_FWDT or BSP_USING_WWDT can be defined when RT_USING_WDT is enabled." | |
| #endif | |
| #if defined(BSP_USING_FWDT) | |
| #define HW_WDGT_DEV_NAME "fwdgt" | |
| #elif defined(BSP_USING_WWDT) | |
| #define HW_WDGT_DEV_NAME "wwdgt" | |
| #else | |
| #error "Please enable BSP_USING_FWDT or BSP_USING_WWDT when RT_USING_WDT is enabled." |
| time_msec = *(rt_uint32_t*)arg; | ||
| wdgt_count = (rt_uint32_t)((float)((float)1/0.78)*time_msec) + 0x3F; | ||
| wwdgt_config(wdgt_count, window_value, WWDGT_CFG_PSC_DIV8); |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[performance/类别: performance]: Floating-point math in timeout calculation / 超时计算使用浮点运算
English: The WWDT timeout calculation uses floating-point operations ((float)1/0.78) inside the driver. On many embedded targets this pulls in soft-float routines and increases code size and CPU cost. Please replace with an integer/rational approximation and add bounds checking to keep wdgt_count within the hardware-allowed range.
中文:WWDT 超时计算在驱动里使用了浮点运算((float)1/0.78)。在很多嵌入式平台上会引入软浮点库,增加代码体积和 CPU 开销。建议改为整数/分数近似计算,并增加边界检查,确保 wdgt_count 在硬件允许范围内。
| LOG_D("hwtimer sample run failed! can't find %s device!", HW_WDGT_DEV_NAME); | ||
| return -RT_ERROR; |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[error_message/类别: error_message]: Copy-pasted error message refers to hwtimer / 复制粘贴导致错误信息指向 hwtimer
English: The error message says "hwtimer sample run failed" inside the watchdog sample. This is misleading when debugging. Please update the message to refer to WDT/WWDT/FWDT consistently.
中文:看门狗示例中的错误日志写成了 "hwtimer sample run failed",会误导排查问题。建议将日志内容统一改为与 WDT/WWDT/FWDT 相关的描述。
| config BSP_USING_FWDT | ||
| bool "Enable FWDT" | ||
| default y | ||
| config BSP_USING_WWDT | ||
| bool "Enable WWDT" | ||
| default n |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[api_design/类别: api_design]: WDT type selection allows invalid combinations / WDT 类型选择可能产生无效组合
English: BSP_USING_FWDT and BSP_USING_WWDT are independent bools under BSP_USING_WDT, so users can select both or neither. The driver assumes exactly one is defined (it needs HW_WDGT_DEV_NAME and selects different implementations). Please model this as a choice (FWDT vs WWDT) or add mutual depends on constraints and ensure at least one option is selected.
中文:在 BSP_USING_WDT 下,BSP_USING_FWDT 和 BSP_USING_WWDT 是两个独立的 bool,用户可能同时选中或都不选。驱动实现假设只会定义其中一个(需要 HW_WDGT_DEV_NAME 并选择不同实现)。建议改为 choice(FWDT/WWDT 二选一),或增加互斥 depends on 约束并保证至少选择一个。
| config BSP_USING_FWDT | |
| bool "Enable FWDT" | |
| default y | |
| config BSP_USING_WWDT | |
| bool "Enable WWDT" | |
| default n | |
| choice | |
| prompt "Select WDT type" | |
| default BSP_USING_FWDT | |
| config BSP_USING_FWDT | |
| bool "Enable FWDT" | |
| config BSP_USING_WWDT | |
| bool "Enable WWDT" | |
| endchoice |
|
|
||
|
|
||
|
|
||
|
|
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[bug/类别: bug]: Missing required device header include / 缺少必要的设备头文件包含
English: This file uses rt_watchdog_t, rt_watchdog_ops, and RT_DEVICE_CTRL_WDT_* APIs, but it only includes <rtthread.h>. In this codebase those watchdog types/macros are provided via <rtdevice.h> (and drivers/dev_watchdog.h), so this will fail to compile when WDT is enabled.
中文:该文件使用了 rt_watchdog_t、rt_watchdog_ops 以及 RT_DEVICE_CTRL_WDT_* 等接口,但只包含了 <rtthread.h>。在本仓库中这些定义来自 <rtdevice.h>(以及 drivers/dev_watchdog.h),因此开启 WDT 后会编译失败。
| #include <rtdevice.h> |
| ErrStatus res = fwdgt_prescaler_value_config(FWDGT_PSC_DIV32); | ||
| res = fwdgt_reload_value_config(wdgt_count); |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[bug/类别: bug]: Undefined/incorrect FWDT configuration API usage / FWDT 配置 API 使用错误或未定义
English: The FWDT timeout path calls fwdgt_prescaler_value_config() and fwdgt_reload_value_config(), but these symbols are not present anywhere else in this repository (search only finds them here). This will cause a link/compile failure. Please switch to the actual FWDT configuration API used by the vendor library (e.g., fwdgt_write_enable() + fwdgt_config(reload, prescaler)), and handle its return value.
中文:FWDT 超时设置分支调用了 fwdgt_prescaler_value_config() 和 fwdgt_reload_value_config(),但这两个符号在仓库其他地方不存在(搜索仅在此处命中),会导致编译/链接失败。建议改用芯片库真实提供的配置接口(如 fwdgt_write_enable() + fwdgt_config(reload, prescaler)),并检查返回值。
| ErrStatus res = fwdgt_prescaler_value_config(FWDGT_PSC_DIV32); | |
| res = fwdgt_reload_value_config(wdgt_count); | |
| /* configure FWDT: enable write access, then set reload and prescaler */ | |
| ErrStatus res = fwdgt_write_enable(); | |
| if (res == SUCCESS) | |
| { | |
| res = fwdgt_config(wdgt_count, FWDGT_PSC_DIV32); | |
| } | |
| if (res != SUCCESS) | |
| { | |
| LOG_E("failed to config FWDT, timeout=%d sec,count=%d res=%d", time_sec, wdgt_count, res); | |
| return -RT_ERROR; | |
| } |
| /* set timeout sec*/ | ||
| time_sec = *(rt_uint32_t*)arg; | ||
| wdgt_count = 32*1000/32*time_sec; | ||
| ErrStatus res = fwdgt_prescaler_value_config(FWDGT_PSC_DIV32); | ||
| res = fwdgt_reload_value_config(wdgt_count); | ||
| LOG_D("timeout=%d sec,count=%d res=%d ", time_sec, wdgt_count, res); | ||
| #elif defined(BSP_USING_WWDT) | ||
| /* set timeout ms */ | ||
| window_value = 0x7F; | ||
| time_msec = *(rt_uint32_t*)arg; | ||
| wdgt_count = (rt_uint32_t)((float)((float)1/0.78)*time_msec) + 0x3F; | ||
| wwdgt_config(wdgt_count, window_value, WWDGT_CFG_PSC_DIV8); | ||
| LOG_D("timeout=%d msec,count=%d ", time_msec, wdgt_count); |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[api_design/类别: api_design]: RT watchdog timeout unit mismatch (seconds vs ms) / 看门狗超时单位与 RT 接口不一致(秒 vs 毫秒)
English: RT_DEVICE_CTRL_WDT_SET_TIMEOUT is defined as “timeout in seconds” (see components/drivers/include/drivers/dev_watchdog.h), but the WWDT branch treats the argument as milliseconds (time_msec) and the sample passes 40. This breaks the standard watchdog device contract and will confuse users/applications. Please keep the control argument in seconds (and convert internally if needed) or expose a separate, clearly documented control command.
中文:RT_DEVICE_CTRL_WDT_SET_TIMEOUT 在 components/drivers/include/drivers/dev_watchdog.h 中定义为“单位:秒”,但 WWDT 分支把参数当成毫秒(time_msec)处理,示例也传入 40。这会破坏标准 watchdog 设备接口契约并误导应用。建议保持控制参数单位为秒(内部再换算),或提供单独且清晰文档化的控制命令。
| /* set timeout sec*/ | |
| time_sec = *(rt_uint32_t*)arg; | |
| wdgt_count = 32*1000/32*time_sec; | |
| ErrStatus res = fwdgt_prescaler_value_config(FWDGT_PSC_DIV32); | |
| res = fwdgt_reload_value_config(wdgt_count); | |
| LOG_D("timeout=%d sec,count=%d res=%d ", time_sec, wdgt_count, res); | |
| #elif defined(BSP_USING_WWDT) | |
| /* set timeout ms */ | |
| window_value = 0x7F; | |
| time_msec = *(rt_uint32_t*)arg; | |
| wdgt_count = (rt_uint32_t)((float)((float)1/0.78)*time_msec) + 0x3F; | |
| wwdgt_config(wdgt_count, window_value, WWDGT_CFG_PSC_DIV8); | |
| LOG_D("timeout=%d msec,count=%d ", time_msec, wdgt_count); | |
| /* set timeout sec */ | |
| time_sec = *(rt_uint32_t*)arg; | |
| wdgt_count = 32*1000/32*time_sec; | |
| ErrStatus res = fwdgt_prescaler_value_config(FWDGT_PSC_DIV32); | |
| res = fwdgt_reload_value_config(wdgt_count); | |
| LOG_D("timeout=%d sec,count=%d res=%d ", time_sec, wdgt_count, res); | |
| #elif defined(BSP_USING_WWDT) | |
| /* set timeout sec (convert to ms internally) */ | |
| window_value = 0x7F; | |
| time_sec = *(rt_uint32_t*)arg; | |
| time_msec = time_sec * 1000U; | |
| wdgt_count = (rt_uint32_t)((float)((float)1/0.78)*time_msec) + 0x3F; | |
| wwdgt_config(wdgt_count, window_value, WWDGT_CFG_PSC_DIV8); | |
| LOG_D("timeout=%d sec (%d msec), count=%d ", time_sec, time_msec, wdgt_count); |
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
add wdt support for gd32vw553h

你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up